package se.webbzon.boltzmann.object.geometry;

import se.webbzon.oschi01.collision3d.CollisionNode3D;
import se.webbzon.oschi01.worldeditor.DeflatableWorldObject;
import se.webbzon.oschi01.worldobject.WorldStaticObject;
import se.webbzon.oschi01.worldobject.appearance.Appearance3DException;
import se.webbzon.oschi01.worldobject.appearance.MutableAppearance3D;

public class Geometry extends WorldStaticObject implements MaskedGeometry, DeflatableWorldObject {
	
	// The name of this world object
	public static String worldObjectName = "geometry";
	
	// The appearance of this geometry
	private GeometryAppearance appearance;
	
	// The mask of this geometry
	private GeometryMask mask;
	
	/*============================================================
	Constructors
	============================================================*/

	/** Creates a new abstract geometry by using a geometry appearance
	 * and a geometry mask. **/
	public Geometry(GeometryAppearance appearance, boolean visible, 
					GeometryMask mask, boolean solid) 
									throws Appearance3DException {
		super(0,new MutableAppearance3D(appearance.getAppearance()));
		this.appearance = appearance;
		setGeometryMask(mask);
		setVisible(visible);
		setSolid(solid);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void setGeometryAppearance(GeometryAppearance appearance) 
			throws Appearance3DException {
		((MutableAppearance3D) getAppearance()).setAppearance(appearance.getAppearance());
		this.appearance = appearance;
	}
	
	@Override public void setGeometryMask(GeometryMask mask) {
		if (mask == null)
			super.setMask(null);
		else
			super.setMask(mask.getMask());
		this.mask = mask;
	}
	
	@Override public GeometryAppearance getGeometryAppearance() {
		return appearance;
	}
	
	@Override public GeometryMask getGeometryMask() {
		return mask;
	}
	
	/** Not supported by geometries. **/
	@Override public void setMask(CollisionNode3D mask) {
		return;
	}

	@Override public String getName() {
		return worldObjectName;
	}

	@Override public GeometryDeflation getDeflation() {
		return new GeometryDeflation(0,this);
	}
	
}
